package com.cy.utilcommond;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.cy.app.Log;

public class MainActivity extends AppCompatActivity {
//genDefine_start
    private TextView mtv;
    private Button mbtn;
    private EditText met;
    private View.OnClickListener mOnClickListener;
    //genDefine_end
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //genFindClick_start
        mtv = (TextView)findViewById(R.id.mtv);
        mbtn = (Button)findViewById(R.id.mbtn);
        met = (EditText)findViewById(R.id.met);

        mOnClickListener=new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                switch (v.getId()){
                    case R.id.mbtn:
                        String command=met.getText().toString();
                        ShellUtils.CommandResult commandResult =
                                ShellUtils.execCommand(command,true,true);
                        mtv.setText("result:"+commandResult.result+" success msg:"
                                +commandResult.successMsg
                                +" error msg:"+commandResult.errorMsg);
/*                        ArrayList<String> commands=new ArrayList<>();
                        commands.add("cd system");
                        commands.add("ls");

                        ShellUtils.CommandResult commandResult =
                                ShellUtils.execCommand(commands,false,true);

                        Log.writeW("result:"+commandResult.result+" success msg:"
                                +commandResult.successMsg
                                +" error msg:"+commandResult.errorMsg);*/
                    break;
                }
            }
        };
        mbtn.setOnClickListener(mOnClickListener);
        //genFindClick_end
    }

    private boolean checkRoot() {
        boolean isRooted= ShellUtils.checkRootPermission();
        Log.w("isRooted:"+isRooted);
        return isRooted;
    }
}
